7 typedef pair
<int, int> point
;
9 int dj
[] = {-2, -1, +1, +2, +2, +1, -1, -2};
10 int di
[] = {-1, -2, -2, -1, +1, +2, +2, +1};
14 while (cin
>> s
>> t
){
15 point
start(s
[0]-'a', s
[1]-'1');
16 point
end(t
[0]-'a', t
[1]-'1');
19 queue
<pair
<point
, int> > q
;
20 q
.push(make_pair(start
, 0));
23 int dist
= q
.front().second
;
24 point u
= q
.front().first
;
26 if (0 <= u
.first
&& u
.first
< 8 &&
27 0 <= u
.second
&& u
.second
< 8 && !visited
.count(u
)){
28 //cout << "Visiting " << u.first << " " << u.second << endl;
30 cout
<< "To get from "<<s
<<" to "<<t
<<" takes "<<dist
<<" knight moves." << endl
;
34 for (int k
=0; k
<8; ++k
){
35 q
.push(make_pair(point(u
.first
+ di
[k
], u
.second
+ dj
[k
] ), dist
+ 1));